package domain.message;

import junit.framework.Assert;
import junit.framework.TestCase;

public class DirectoryTest extends TestCase {

	Thread currForumThread;
	Directory currSubForum;

	/**
	 * function which creates a new Subforum and a new forumThread with the topic topic
	 *  and the name name,
	 * so we could test the other functions
	 */
	public void setUp(final String topic,final String name)
	{
		this.currForumThread = new Thread(0, topic);
		this.currSubForum = new Directory(0, name);
	}

	/**
	 * checks if the ForumThread was added to the SubForum
	 */
	public void testAddForumThread() {
		this.setUp("exams","third year");
		Assert.assertEquals(false, this.currSubForum.getThreads().contains(this.currForumThread.getId()));
		this.currSubForum.addThread(this.currForumThread.getId());
		Assert.assertEquals(true, this.currSubForum.getThreads().contains(this.currForumThread.getId()));

	}

	/**
	 * checks if the SubForum was added to children of the SubForum
	 */
	public void testAddSubforum() {
		this.setUp("exams","third year");
		final Directory tempChild = new Directory(1, "second year");
		Assert.assertEquals(false, this.currSubForum.getChildren().contains(tempChild.getId()));
		this.currSubForum.addDirectory(tempChild.getId());
		Assert.assertEquals(true, this.currSubForum.getChildren().contains(tempChild.getId()));

	}

	/**
	 * checks if the ForumThread was deleted from the SubForum
	 */
	public void testDeleteForumThread() {
		this.setUp("exams","third year");
		this.currSubForum.addThread(this.currForumThread.getId());
		Assert.assertEquals(true, this.currSubForum.getThreads().contains(this.currForumThread.getId()));
		this.currSubForum.deleteThread(this.currForumThread.getId());
		Assert.assertEquals(false, this.currSubForum.getThreads().contains(this.currForumThread.getId()));

	}

	/**
	 * checks if the SubForum was deleted from the children of the SubForum
	 */
	public void testDeleteSubforum() {
		this.setUp("exams","third year");
		final Directory tempChild = new Directory(1, "second year");
		this.currSubForum.addDirectory(tempChild.getId());
		Assert.assertEquals(true, this.currSubForum.getChildren().contains(tempChild.getId()));
		this.currSubForum.deleteDirectory(tempChild.getId());
		Assert.assertEquals(false, this.currSubForum.getChildren().contains(tempChild.getId()));

	}

}
